<style>
/*评论*/
.review_list{margin:10px auto;background:#FFFFFF;}
.list_title{height:37px;line-height:37px;font-family:"黑体";font-size:16px;padding-left:20px;background:#f7f7f7;border-top:#fff 1px solid}
.review_list_main dl{margin:12px;border-bottom:#dddddd 1px dotted;}
.review_list_main dt{color:#999}
.review_list_main dd{margin-top:8px;padding-bottom:5px;color:#333}
.review_list_main span.uesr_com{background:#f7f7f7;border:#dfdfdf 1px solid;padding:10px;display:block;margin:10px}
.review_page{text-align:center;padding:10px 0;}
.review_page a{background:url(./page_bg.gif) repeat-x;height:18px;line-height:18px;
border-top:#aacce8 1px solid;;border-bottom:#aacce8 1px solid;
border-left:#dae9f5 1px solid;border-right:#dae9f5 1px solid;display:inline-block;
padding:0 5px;color:#5e5e5e;margin:2px;text-decoration:none;cursor:pointer;}
.review_page a img{vertical-align:middle;margin:0 3px}
.review_page a:hover{background:#62c1ee;color:#fff}
.review_list .post{text-align:right;margin-top:10px;width:98%}
.review_list_main{margin:10px 0}
.box_sina{width:674px;margin:10px auto}
.com_info{margin:0 auto 10px;width:96%;padding-top:5px;}
.com_info b{color:#666;font-weight:100;margin-left:10px}
.com_info input{margin:0 10px;vertical-align:middle}
.com_info .rev_box{border:#dddddd 1px solid;height:22px;line-height:24px}
.com_info .rev_btn{background:url(./sub_btn.gif) no-repeat;width:59px;height:22px;line-height:22px;border:0;color:#fff;font-weight:700;cursor:pointer}
.com_con{border:#ddd 1px solid;margin:10px auto;width:96%}
.com_con_title{background:#f7f7f7;border-bottom:#ddd 1px solid;height:25px;line-height:25px}
.com_con_title img{vertical-align:middle;margin-left:10px}
.com_con .com_mian{width:100%;overflow:hidden;border:0;min-height:100px;background:#FFFFFF;}

#answer img{margin:2px 8px;vertical-align:middle}
#answer #auth { vertical-align:middle;width:40px;height:22px;line-height:22px;border:#ccc 1px solid} 
.newshow_left_msgfrm_left{overflow:hidden;font-size:12px;color:#999;padding-left:5px;background:#eee;height:24px;line-height:24px}
.newshow_left_msgfrm_right{ width:92%;font-size:12px; color:#333333; text-align:left; padding:10px;line-height:22px}
.newshow_left_msgfrm_right p{}
.newshow_left_msgfrm_right a{color:#999}
.newshow_left_msgfrm_right a:hover{color:#f90}
.newshow_left_msgfrm_btmline{overflow:hidden;width:100%;margin:0 auto 10px;}
.btn_post{background:#44abe2;padding:3px 12px;color:#fff;border:#288dc3 1px solid;text-align:center;border-radius:3px}
.review_ping{width:960px;margin:20px auto 0}
</style>

<div class="review_list" id="msg_content">
		<div class="review_ping">
                    <div class="com_info clearfix"><span class="f_l"><b></b></span></div>
			<div class="com_con">
				<textarea class="com_mian"  name="content" id="content"></textarea>
			</div>
			<div class="post">
			<span id="answer"><img src="<?php echo COMMENT_ROOT ?>/comment/rand.php" /><input type="text" name="auth" id="auth" /></span>
			<input id="sub_msg" type="button" value="发 表" class="btn_post"/></div>
				<div class="review_list_main clearfix">
		<div class="txtcon_b">
		<span class ="facessss"  id="show_msg_content"></span>
		</div>
	</div>
	</div><div class="review_page" id="pageNav"></div> 
</div>

<script>
var args = [];
args['id'] = <?php echo intval($id);?>;
args['url'] = "<?php echo COMMENT_ROOT;?>/comment/";
args['cookiename'] = "<?php echo $comment['cookiename']; ?>";
run(args);

function has_chinese(s){ 
	var patrn=/[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/gi; 
	if(!patrn.exec(s)) return false; 
	else return true; 
} 
function is_legal(c) {
	if(c.indexOf('www.')!==-1 || c.indexOf('url=http://')!==-1 || c.indexOf('http://')!==-1 ||c.indexOf('.com')!==-1) {
		return false;
	}else{
		return true;
	}
}

//取cookies函数       
function getCookie(name) {
  var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
   if(arr != null) return unescape(arr[2]); return null;
}

function show_list(args, pag) {
	$.ajax({
		type:'POST',
		datatype:'json',
		url:args['url']+'index.php',
		data:{'id':args['id'], 'pag':pag},
		success:function(info){
			var data = eval("("+info+")");
            if(data && data.tol!=='0'){
                var list=data.list;   
                var comment = '';
                $.each(list,function(i,n){
                	comment += '<div class="newshow_left_msgfrm_btmline clearfix">';
                	comment += '<div class="newshow_left_msgfrm_left">';
                	comment += '<font color="#006699"><strong>'+n['username']+'</strong></font> '+n['ctime']+'</div>';
                    comment += '<div id="user_box_'+n.id+'" class="newshow_left_msgfrm_right">'+n.content+'</div>';
                });

                $("#show_msg_content").html(comment);             
                $("#pageNav").html(data.pager);
                $('span.f_l b').html('评论区(已有'+data.tol+'条评论)');
              
            }
		}
	});
}

function check_answer(answer, right, url) {
	if($.trim(answer)==''){
        alert('请输入验证码');
        fresh_rand(url);
        return false;
    }
	if(isNaN(answer)) {
		alert('请输入数字');
		fresh_rand(url);
		return false;
	}
    
    if(answer!=void(0)){
        if(right!=answer){
            alert('验证码有误');
            fresh_rand(url);
            return false;
        }
    }else return true;
}

function check_content(c, url) {
	if($.trim(c)==''){		
        alert('评论不能为空');
        fresh_rand(url);
        return false;
    }
    if(!is_legal(c)) {
		alert('亲,你填入的信息包括URL字符');
		fresh_rand(url);
		return false;
	}			
	if(c.length>100) {
		alert("亲,留言内容必须在100字以内,请修改长度");
		fresh_rand(url);
		return false;
	}
}

function fresh_rand(url) {
	var obj = $('div.review_ping div.post span#answer img');
	var href=obj.attr("src");
    $(obj[0]).attr("src",href+"?time="+new Date().getTime());
}

function post_comment(c, answer, args) {
    if(false==check_content(c, args['url'])) return false;
    var right = parseInt(getCookie(args['cookiename']));
    if(false==check_answer(answer, right, args['url'])) return false;

    //var uid=$("#login_info").attr("userid")||'0';  //获取登录用户ID
   var username=$("#login_info").attr("username")||'XDA网友';  //获取登录用户名称
	var date = new Date();			
	var cont = '<div class="newshow_left_msgfrm_btmline clearfix">'+
	'<div class="newshow_left_msgfrm_left">'+
		'<font color="#006699"><strong>'+username+'</strong></font>'+
		'于'+date.getFullYear()+'年'+date.getDate()+'月'+date.getHours()+':'+date.getMinutes()+':'+date.getSeconds()+'说：'+
	'</div> <div class="newshow_left_msgfrm_right">'+c+' </div>';

	var reply_num = $('div.txtcon_b span#show_msg_content div.newshow_left_msgfrm_btmline').length;
	if(reply_num>=5) $("div.txtcon_b span#show_msg_content div.newshow_left_msgfrm_btmline:last").fadeOut(); //评论数大于5个 把最后一个隐藏掉

	if(reply_num==0 ) {$("div.txtcon_b span#show_msg_content").append(cont);}
	else{ 
		$("div.txtcon_b span#show_msg_content div.newshow_left_msgfrm_btmline:first").before(cont);
	}
	$.post(args['url']+'index.php', {"cfid":args['id'], "username":username,"auth":answer, "content":c},function(data){		 
		 //if(sta==1) alert('评论已提交,需要后台审核');
		 $('div.review_ping div.com_con textarea').attr('value', '');//清空内容
		 $('span#answer input#auth').attr('value', '');//清空验证码
	     fresh_rand(args['url']);
	       
	},'json');
	
}

function load_jq(url) {
	if(typeof jQuery !='undefined') return;
	
    //var script = document.createElement("script");
    //script.type = "text/javascript";
    //script.src = url+'jquery.min.js';
    //document.getElementsByTagName("head")[0].appendChild(script);
	document.write('<script type="text/javascript" src="'+url+'jquery.min.js"><\/script>');
}

function loadScript(url,callback) {
    var script=document.createElement("script");
    script.type="text/javascript";
    if(script.readyState){
        script.onreadystatechange=function(){
            if(script.readyState=='loaded'||script.readyState=='complete'){
                script.onreadystatechange=null;
                callback();
            }
        }
    }else{script.onload=function(){callback();}}
    script.src=url;
    document.getElementsByTagName("head")[0].appendChild(script);
}

function main(args) {
	//初始加载第一页
	show_list(args, 1);
	
	//分页
    $("#pageNav a").live("click",function(){
    	var pag = parseInt($(this).attr('rel'));
		show_list(args, pag);
     });
	
  //提交评论
    $('input#sub_msg').click(function() {
    	var c = $('textarea#content').val();
    	var answer = parseInt($.trim($('input#auth').val()));
    	post_comment(c, answer, args);
    });
}

function run(args) {
	if(typeof jQuery!='function') {
		loadScript(args['url']+'jquery.min.js',function(){
			main(args);
		});
	}else{
		$(function(){
			main(args);
		});
	}
}
</script>